# Contributor: Russ Webber <russ@rw.id.au>
# Maintainer: Russ Webber <russ@rw.id.au>
pkgname=assimp
pkgver=5.4.3
pkgrel=0
pkgdesc="Open Asset Import Library imports and exports 3D model formats"
url="https://www.assimp.org/"
arch="all"
license="BSD-3-Clause"
makedepends="
	cmake
	samurai
	zlib-dev
	"
subpackages="$pkgname-dev $pkgname-libs"
source="https://github.com/assimp/assimp/archive/v$pkgver/assimp-v$pkgver.tar.gz"

case "$CARCH" in
s390x)
	# a few tests fail
	options="$options !check"
	;;
esac

# secfixes:
#   5.4.3-r0:
#     - CVE-2024-40724

prepare() {
	default_prepare

	# tests report correct values, but comparison fails
	case $CARCH in
	x86)
		sed -i \
			-e "/AssimpAPITest_aiMatrix3x3/d" \
			-e "/AssimpAPITest_aiMatrix4x4/d" \
			-e "/utFastAtof/d" \
			test/CMakeLists.txt
		;;
	esac
}

build() {
	cmake -B build -G Ninja \
		-DCMAKE_BUILD_TYPE=MinSizeRel \
		-DCMAKE_INSTALL_PREFIX=/usr \
		-DCMAKE_INSTALL_LIBDIR=lib \
		-DBUILD_SHARED_LIBS=True \
		-DASSIMP_IGNORE_GIT_HASH=ON \
		-DASSIMP_BUILD_ASSIMP_TOOLS=ON \
		-DASSIMP_BUILD_TESTS="$(want_check && echo ON || echo OFF)" \
		-DASSIMP_WARNINGS_AS_ERRORS=OFF \
		-DASSIMP_BUILD_MINIZIP=True  # use vendored fork of minizip
	cmake --build build
}

check() {
	./build/bin/unit
}

package() {
	DESTDIR="$pkgdir" cmake --install build
	rm -vf "$pkgdir"/usr/lib/libIrrXML.a
}

sha512sums="
4738db84068d36face8caf61c0789178fdfc1310fa8e81ffb9b025e14183bde546b784d691c92438ab310a79ab7b75ab62ee0247d5f01e81ddf04fb94b7a9c0b  assimp-v5.4.3.tar.gz
"
